package com.vote.controllers;

import java.lang.annotation.Annotation;

import net.paoding.rose.web.ControllerInterceptorAdapter;
import net.paoding.rose.web.Invocation;

import com.vote.annotation.LoginRequired;
import com.vote.model.User;
import com.vote.utils.HostHelper;
import com.vote.utils.MsgHelper;

public class LoginRequiredInterceptor extends ControllerInterceptorAdapter {

    @Override
    public Class<? extends Annotation> getRequiredAnnotationClass() {
        return LoginRequired.class;
    }

    @Override
    public Object before(Invocation inv) throws Exception {
        User host = HostHelper.getHost(inv.getRequest());
        if(host == null){
        	String url = MsgHelper.rError("http://"  +  inv.getRequest().getServerName()  +  ":"  +  inv.getRequest().getServerPort()  +  inv.getRequest().getContextPath()+"/login",
        			"请先登录～～");
            return "r:"+url;
        }
        return true;
    }
}